package cn.kgc.vue.handler;

import cn.kgc.vue.commons.ResponseResult;
import cn.kgc.vue.exceptions.StudentNoException;
import com.auth0.jwt.exceptions.JWTVerificationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.naming.AuthenticationException;

/**
 * @Author 张航
 * @Date 2024/7/2
 * @Description
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(JWTVerificationException.class)
    public ResponseResult jwtVerificationException(JWTVerificationException e) {
        e.printStackTrace();
        return ResponseResult.error().message("Token异常");
    }

    @ExceptionHandler(Exception.class)
    public ResponseResult   otherException( Exception e){

        e.printStackTrace();

        return  ResponseResult.error().message("服务器繁忙,请刷新重试!!!");
    }

@ExceptionHandler(DuplicateKeyException.class)
    public ResponseResult duplicateKeyException(DuplicateKeyException e) {
        e.printStackTrace();
        return ResponseResult.error().message("添加的数据已存在，请检查");
}


@ExceptionHandler(UnauthorizedException.class)
public ResponseResult UnauthorizedException(UnauthorizedException e) {
    e.printStackTrace();
    return ResponseResult.error().message("没有权限请联系管理员");
}

    @ExceptionHandler(AuthenticationException.class)
    public ResponseResult handleAuthenticationException(AuthenticationException e) {
        e.printStackTrace();
        return ResponseResult.error().message("认证失败，请重新认证");
    }

@ExceptionHandler(StudentNoException.class)
public ResponseResult StudentNoException(StudentNoException e) {
    e.printStackTrace();
    return ResponseResult.error().message(e.getStudentNo()+"已存在");
}






}




